package vip.specimen.web.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import vip.specimen.system.common.enums.QuestionTypeEnum;
import vip.specimen.system.datasource.entity.question.QuestionProblemEntity;
import vip.specimen.system.datasource.validation.question.QuestionProblemValidation;
import vip.specimen.system.result.JsonResult;
import vip.specimen.system.service.question.ProblemService;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;

/**
 * *@Author: 余浪人
 * *@Date：2021/4/29 9:35
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
@Api(tags = "数据管理")
@RestController
@RequestMapping(value = "/manage")
public class ManageController {
    @Resource
    private ProblemService problemService; // TODO 引用失败

    @GetMapping(value = "question/type")
    @ApiOperation(value = "API查看问题类型", notes = "获取全部的问题类型方式")
    public JsonResult<ArrayList<JSONObject>> saveMethod() {
        ArrayList<JSONObject> list = new ArrayList<>();
        for (QuestionTypeEnum type : QuestionTypeEnum.values()) {
            JSONObject map = new JSONObject(3);
            map.put("typeId", type.getTypeId());
            map.put("typeName", type.getTypeName());
            map.put("name", type.name());
            list.add(map);
        }
        return JsonResult.success(list);
    }

    @PostMapping("/question")
    @ApiOperation(value = "API新增", notes = "API接口新增问题")
    public JsonResult<QuestionProblemEntity> insert(@RequestBody @Valid QuestionProblemValidation questionProblemValidation) {
        return JsonResult.success(this.problemService.insert(questionProblemValidation));
    }
}
